<template>
  <div>
    <el-card class="cardBox">
      <div class="title">
        <h1 class="">水处理</h1>
      </div>
      <!-- 调节池 -->
      <div style="">
        <div style="border: 1px solid var(--el-border-color-light)">

           <el-row class="header-row">
          <el-col :span="8"></el-col>
          <el-col :span="8" class="title-col"
            ><span>水处理</span></el-col
          >
          <el-col :span="8" class="status-col">
            <div class="status-container">
              <div>
                <span>通讯故障</span>
                <i class="yuan yellow"></i>
              </div>
              <div>
                <span>无故障</span>
                <i class="yuan grey"></i>
              </div>
              <div>
                <span>运行</span>
                <i class="yuan green"></i>
              </div>
              <div>
                <span>报警</span>
                <i class="yuan red"></i>
              </div>
            </div>
          </el-col>
        </el-row>

          <el-row class="threeTitle">
            <el-col :span="12">调节预沉池1</el-col>
            <el-col :span="12">调节预沉池2</el-col>
          </el-row>

          <el-row>
            <el-col :span="6">参数</el-col>
            <el-col :span="6">
              3.48
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
            <el-col :span="6" class="first-third-col">参数</el-col>
            <el-col :span="6">
              3.47
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">1#行车远程控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="6" class="first-third-col">2#行车远程控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">1#水泵控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="6" class="first-third-col">1#水泵控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">2#水泵控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="6" class="first-third-col">2#水泵控制</el-col>
            <el-col :span="6">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">1#调节池出水流量</el-col>
            <el-col :span="6">
              0.00
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
            <el-col :span="6" class="first-third-col">2#调节池出水流量</el-col>
            <el-col :span="6">
              118.56
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="6">1#调节池出口累计流量</el-col>
            <el-col :span="6">
              20865
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
            <el-col :span="6" class="first-third-col"
              >2#调节池出口累计流量</el-col
            >
            <el-col :span="6">
              8899
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
        </div>
      </div>

      <!-- 污泥处理 -->
      <div style="">
        <div style="border: 1px solid var(--el-border-color-light)">
          <el-row class="threeTitle">
            <el-col :span="24">污泥处理</el-col>
          </el-row>

          <el-row>
            <el-col :span="12"> 污泥池 </el-col>
            <el-col :span="12">
              1.26
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12"> 污泥浓缩罐进口流量 </el-col>
            <el-col :span="12">
              0.00
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12"> 污泥浓缩罐累计流重 </el-col>
            <el-col :span="12">
              6530
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12"> 污泥浓缩罐 </el-col>
            <el-col :span="12">
              3.99
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
        </div>
      </div>

      <!-- 刮泥机 -->
      <div style="">
        <div style="border: 1px solid var(--el-border-color-light)">
          <el-row class="threeTitle">
            <el-col :span="6"></el-col>
            <el-col :span="6">1# 澄清地刮泥机</el-col>
            <el-col :span="6">2# 澄清地刮泥机</el-col>
            <el-col :span="6">3# 澄清地刮泥机</el-col>
          </el-row>

          <el-row>
            <el-col :span="6"> 参数 </el-col>
            <el-col :span="6">
              1.35
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
            <el-col :span="6">
              1.34
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
            <el-col :span="6">
              1.36
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduanGNJ", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
        </div>
      </div>

      <!-- 过滤器 -->
      <div style="">
        <div style="border: 1px solid var(--el-border-color-light)">
          <el-row class="threeTitle">
            <el-col :span="4"></el-col>
            <el-col :span="5">4GLQ 4#石英砂过滤器</el-col>
            <el-col :span="5">3GLQ 3#石英砂过滤器</el-col>
            <el-col :span="5">2GLQ 2#石英砂过滤器</el-col>
            <el-col :span="5">1GLO 1#石英砂过滤器</el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 排气阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 进水阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 出水阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 反洗进水阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 反洗出水阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="4"> 正排出水阀 </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG1', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG2', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG3', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
            <el-col :span="5">
              <span class="hn-span">
                <div
                  class="indicator-light"
                  :class="
                    NamePD_52('ziduanstatusG4', operator.NO).value === 2
                      ? 'red'
                      : 'grey'
                  "
                ></div>
              </span>
            </el-col>
          </el-row>
        </div>
      </div>

      <!-- 滤后水池 -->
      <div style="">
        <div>
          <el-row>
            <el-col :span="12"> 分配水箱 </el-col>
            <el-col :span="12">
              1.08
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduan111", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12"> 澄清产水池 </el-col>
            <el-col :span="12">
              1.20
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduan111", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12"> 滤后水池 </el-col>
            <el-col :span="12">
              2.16
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduan111", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12"> 反洗排水池 </el-col>
            <el-col :span="12">
              0.86
              <!-- <span class="readNumber">
                {{ NamePD_52("numberziduan111", operator.NO, null, 2) }}
              </span> -->
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>

    <!-- 公司log -->
    <el-row>
      <div class="kx-log-box">
        <img
          class="kx-img"
          src="@/assets/images/kxauto.png"
          alt="描述图片的文字"
        />
        <span>开轩自动化</span>

        <span class="kx-hezuo">
          商务合作：18509234888（同微信） 技术支持：18691805301（同微信）
        </span>
      </div>
    </el-row>

    <!-- 弹窗 -->
    <form-dialog ref="formRef" />
    <sensorFormDialog ref="sensorRef" />
    <CoalCutterHeadSwitch ref="coalCutterHeadSwitchRef" />
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import EarthIcon from "@/assets/images/top.svg";
import { ElMessage, ElMessageBox } from "element-plus";
import { act, createWebSocket } from "@/utils/websocket"; //引入websocket
import {
  NamePD_52,
  NamePD_52_PT_52,
  NamePD_52_GEN,
} from "@/utils/beltPositioningMethod.ts";
import { BPQMap } from "@/utils/BPQMap";
import { operator } from "@/utils/op_enums";

import formDialog from "./alarmForm.vue";
import sensorFormDialog from "./sensorForm.vue";
import CoalCutterHeadSwitch from "./coalCutterHeadSwitch.vue";

const formRef = ref();
const sensorRef = ref();
const coalCutterHeadSwitchRef = ref();
const HUANINGBH = [
  "HNLineLock1_DI",
  "HNLineLock2_DI",
  "HNLineLock4_DI",
  "HNLineLock5_DI",
  "HNLineLock6_DI",
  "HNLineLock7_DI",
  "HNLineLock8_DI",
  "HNLineLock9_DI",
  "HNLineLock10_DI",
  "HNLineLock11_DI",
  "HNLineLock12_DI",
  "HNLineLock13_DI",
  "HNLineLock14_DI",
  "HNLineLock15_DI",
  "HNLineLock16_DI",
  "HNLineLock17_DI",
  "HNLineLock18_DI",
  "HNLineLock19_DI",
  "HNLineLock20_DI",
  "HNLineLock21_DI",
  "HNLineLock22_DI",
  "HNLineLock23_DI",
  "HNLineLock24_DI",
  "HNLineLock25_DI",
  "HNLineLock26_DI",
  "HNLineLock27_DI",
  "HNLineLock28_DI",
  "HNLineLock29_DI",
  "HNLineLock3_DI",
  "HNLineLock30_DI",
  "HNLineLock31_DI",
  "HNLineLock32_DI",
  "HNLineLock33_DI",
  "HNLineLock34_DI",
  "HNLineLock35_DI",
  "HNLineLock36_DI",
  "HNLineLock37_DI",
  "HNLineLock38_DI",
];
// const NamePD_52 = (
//   key: string,
//   op: operator,
//   op_number?: number,
//   retain?: number
// ) =>
//   computed(() => {
//     return useTagResults(act.PD_52.PD_52[key], op, op_number, retain);
//   });
// const NamePD_52_PT_52 = (
//   key: string,
//   op: operator,
//   op_number?: number,
//   retain?: number
// ) =>
//   computed(() => {
//     return useTagResults(act.PD_52.PD_52_PT_52[key], op, op_number, retain);
//   });
// const NamePD_52_GEN = (
//   key: string,
//   op: operator,
//   op_number?: number,
//   retain?: number
// ) =>
//   computed(() => {
//     return useTagResults(act.PD_52.PD_52_GEN[key], op, op_number, retain);
//   });
onMounted(() => {
  createWebSocket("%PD_52%");
});
// svg 元素引用
const svgRef = ref<InstanceType<typeof EarthIcon>>();

const alarmBtn = () => {
  formRef.value.openDialog();
};
const sensorBtn = () => {
  sensorRef.value.openDialog();
};
const switchBtn = () => {
  coalCutterHeadSwitchRef.value.openDialog();
};
const faultResetBtn = () => {
  ElMessage.info("故障复位");
};
</script>

<style lang="scss" scoped>
.cardBox {
  background-color: var(--el-bg-color);
  border-radius: 8px;
  box-shadow: var(--el-box-shadow-light);
  border: 1px solid var(--el-border-color-light);

  /* 左上方标题 */
  .title {
    border-bottom: 1px solid var(--el-border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h1 {
      color: var(--el-text-color-primary);
      font-size: 20px;
      margin: 0;
      font-weight: 500;
    }

    .el-button {
      background-color: var(--el-color-danger);
      color: var(--el-color-white);
      border: none;
      border-radius: 4px;
      padding: 8px 15px;
      font-weight: 500;

      &:hover {
        background-color: var(--el-color-danger-light-3);
      }
    }
  }

  /* 表格标题 + 四个指示灯 */
  .header-row {
    display: flex;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    font-weight: 500;
    color: var(--el-text-color-primary);
    padding: 10px;
    .el-col {
      height: 40px;
      display: flex;
      align-items: center;
      border: 1px solid transparent;
    }

    .title-col {
      justify-content: center;

      span {
        font-size: 18px;
      }
    }

    .status-col {
      justify-content: end;
      .status-container {
        display: flex;
        gap: 14px;

        div {
          background: var(--el-fill-color-blank);
          border: 1px solid var(--el-border-color-lighter);
          border-radius: 4px;
          padding: 4px 8px;
          display: flex;
          align-items: center;
          gap: 6px;
          font-size: 13px;

          span {
            padding: 0 4px;
          }

          .yuan {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            flex-shrink: 0;
            @extend %status-colors;
          }
        }
      }
    }
  }

  /* 表格的标题 项目 + 状态值 */
  .threeTitle {
    .el-col {
      background-color: var(--el-fill-color) !important;
    }
  }

  /* 每一小格子的边框 背景色 */
  .el-col {
    border: 1px solid var(--el-border-color-lighter);
    text-align: center;
    padding: 6px 5px;
    font-size: 13px;
    color: var(--el-text-color-regular);

    &:first-child,
    &.first-third-col {
      font-weight: 500;
      // color: blue;
      color: var(--el-text-color-primary);
      background-color: var(--el-fill-color-lighter);
    }
  }

  /* 子页面设备参数--指示灯 */
  .indicator-light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--el-border-color);
    margin: 0 auto;
    @extend %status-colors;
  }

  /* 华宁沿线闭锁 */
  .huaning-title {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--el-text-color-primary);
    font-weight: 500;
  }

  .hn-container {
    display: flex;
    flex-wrap: wrap;
    gap: 50px;
    padding: 8px;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;

    span {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .hn-span {
      display: inline-flex;
      align-items: center;
    }
  }

  .index-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    justify-content: flex-start;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;
    min-height: 40px;
    align-items: center;
  }

  .index-circle {
    width: 26px;
    height: 26px;
    background-color: var(--el-border-color);
    border-radius: 50%;
    color: var(--el-text-color-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    @extend %status-colors;
  }

  // 定义基础颜色类（只定义一次）
  %status-colors {
    &.green {
      background-color: var(--el-color-success);
    }
    &.red {
      background-color: var(--el-color-danger);
    }
    &.yellow {
      background-color: var(--el-color-warning);
    }
    &.grey {
      background-color: var(--el-border-color-dark); // 比默认边框色更深的灰色
    }
  }
}
</style>
